package com.awei.study.design.found.singleton;

/**
 * @Author liweilong
 * @Date 2025/2/12 9:07
 */
public class Total {

    static class Singleton {

        private static Singleton singleton = new Singleton();

        private Singleton() {

        }

        public static Singleton getSingleton() {
            return  singleton;
        }

    }


    static class Singleton1 {

        private static Singleton1 singleton;

        private Singleton1() {

        }

        public static Singleton1 getSingleton() {
            if(singleton  == null) {
                singleton = new Singleton1();
            }
            return  singleton;
        }

    }

    static class Singleton2 {

        private static Singleton2 singleton;

        private static final  Object lock = new Object();

        private Singleton2() {

        }

        public static Singleton2 getSingleton() {
            if(singleton  == null) {
                synchronized (lock) {
                    if(singleton == null) {
                        singleton = new Singleton2();
                    }
                }
            }
            return  singleton;
        }

    }

    static class Singleton3 {

        private static Singleton3 singleton;

        private static final  Object lock = new Object();

        private Singleton3() {

        }

        public static Singleton3 getSingleton() {
            return singleton;
        }

    }

    static Enum Singleton4 {
        String a,
                String b,
                        String c;



    }

}
